#include <stdio.h>
int main()
{
    //freopen("in.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        if(i%3 == 0) printf(" %d",i);
        else
        {
            int k = i;
            while (k)
            {
                if(k%10 == 3)
                {
                    printf(" %d",i);
                    break;
                }
                k = k / 10;
            }
        }
    }
    printf("\n");
}